from PyQt5.QtCore import QDateTime
from PyQt5.QtWidgets import QLineEdit, QApplication, QWidget, QVBoxLayout
import sys


class MyWidget(QWidget):
    def __init__(self):
        super().__init__()

        # 创建一个 QLineEdit 用于显示和编辑时间
        self.time_edit = QLineEdit(self)
        self.time_edit.setPlaceholderText("YYYY-MM-DD HH:MM:SS")  # 设置占位符
        self.time_edit.setText(QDateTime.currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))  # 设置默认时间为当前时间

        # 布局
        layout = QVBoxLayout()
        layout.addWidget(self.time_edit)
        self.setLayout(layout)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    widget = MyWidget()
    widget.show()
    sys.exit(app.exec_())
